package com.hxy.springcloud.service;

import com.hxy.springcloud.pojo.Department;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

//服务降级
@Component
public class DeptClientServiceFallbackFactory implements FallbackFactory {
    @Override
    public DeptClientService create(Throwable throwable) {

        return new DeptClientService() {
            @Override
            public boolean addDepartment(Department department) {
                return false;
            }

            @Override
            public Department queryById(long id) {
                //避免空指针，尽量不要返回null
                return new Department().setDepartId(id)
                        .setDName("id=" + id + "没有对应的信息，客户端提供了降级的信息，这个服务现在已经被关闭！")
                        .setDb_source("no database");
            }

            @Override
            public List<Department> queryAllDepartment() {
                return null;
            }
        };
    }
}
